﻿using System;
using System.Data;

namespace HRM.BusinessLogic
{
    public class ReturnInsBookInfo : Standard_Info
    {
        public int ReturnInsBook_Id { get; set; }
        public string ReturnInsBook_SiBookNo { get; set; }
        public string ReturnInsBook_CardNo { get; set; }
        public int ReturnInsBook_EmployeeId { get; set; }
        public string ReturnInsBook_FullName { get; set; }
        public int ReturnInsBook_Type { get; set; }
        public int ReturnInsBook_BranchId { get; set; }
        public DateTime ReturnInsBook_Date { get; set; }
        public DateTime ReturnInsBook_CreateDate { get; set; }
        public DateTime ReturnInsBook_LastUpdate { get; set; }

    }

    public class ReturnInsBook_Controller : Standard_Controller
    {
        #region "Contructor"
        private static ReturnInsBook_Controller _instance;
        protected ReturnInsBook_Controller() { }
        protected new void Dispose()
        {
            _instance = null;
        }
        private static object _syncLock = new object();
        public static ReturnInsBook_Controller Instance()
        {
            if (_instance == null)
            {
                lock (_syncLock)
                {
                    if (_instance == null)
                        _instance = new ReturnInsBook_Controller();
                }
            }
            return _instance;
        }
        public static ReturnInsBook_Controller Instance(String transName)
        {
            if (!String.IsNullOrEmpty(transName))
            {
                var _instanceTrans = new ReturnInsBook_Controller { Trans_Name = transName };
                return _instanceTrans;
            }
            return Instance();
        }

        #endregion

        public const String CS_TABLE_NAME = "";

        public ReturnInsBookInfo ReturnInsBook_GetInfo(int returnInsBookId)
        {
            return CBO.FillObject<ReturnInsBookInfo>(DataConnect.ExecuteRow(DataConnect.WorkingConnect, Procedure_Name(CS_TABLE_NAME, "HRM_ReturnInsBook_GetInfo"), returnInsBookId));
        }

        public DataTable ReturnInsBook_GetAll(int branchId, int type, int PageIndex, int PageSize, string PageOrder)
        {
            return DataConnect.ExecuteTable(DataConnect.WorkingConnect, Procedure_Name(CS_TABLE_NAME, "HRM_ReturnInsBook_GetAll"), branchId, type
                , PageIndex
                , PageSize
                , PageOrder
                );
        }


        public int ReturnInsBook_Insert(ReturnInsBookInfo eInfo)
        {
            return Globals.Object_GetValue<int>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(CS_TABLE_NAME, "HRM_ReturnInsBook_Insert"),
                eInfo.ReturnInsBook_SiBookNo,
                eInfo.ReturnInsBook_CardNo,
                eInfo.ReturnInsBook_EmployeeId,
                eInfo.ReturnInsBook_FullName,
                eInfo.ReturnInsBook_Type,
                eInfo.ReturnInsBook_BranchId
            ));
        }

        public bool ReturnInsBook_Update(ReturnInsBookInfo eInfo)
        {
            return Globals.Object_GetValue<bool>(DataConnect.ExecuteScalar(DataConnect.WorkingConnect, Procedure_Name(CS_TABLE_NAME, "HRM_ReturnInsBook_Update"),
                eInfo.ReturnInsBook_Id,
                eInfo.ReturnInsBook_Type
                ));
        }

        public bool ReturnInsBook_Delete(int returnInsBookId)
        {
            return DataConnect.ExecuteNonQuery(DataConnect.WorkingConnect, Procedure_Name(CS_TABLE_NAME, "HRM_ReturnInsBook_Delete"), returnInsBookId) > 0;
        }
    }
}
